package com.shuqi.model;

import java.util.List;

import org.apache.http.message.BasicNameValuePair;

import android.content.Context;

import com.shuqi.common.MyTask;
import com.shuqi.common.Urls;
import com.shuqi.model.net.HttpRequest;
import com.shuqi.model.net.UrlManager;
import com.shuqi.model.net.listener.HttpRequestListener;
import com.shuqi.model.parse.parser.NoticeParser;
import com.shuqi.model.parse.parser.RecommendParser;

public class RecommendModel extends ModelBase implements HttpRequestListener {
    private HttpRequest httpRequest;
    private Context context;
    private String notice = "";

    public RecommendModel(Context context) {
        this.context = context;
    }

    @Override
    public void action(int actionCode, Object object) {
        fireEvent(actionCode, object);
    }

    @Override
    public List<BasicNameValuePair> setParams() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public String getRequestUrl() {
        if ("recommend".equals(notice)) {
            return Urls.getRecommendUrl();
        } else {
            return Urls.getNoticeUrl();
        }
    }

    @Override
    public void onDestroy() {
        if (httpRequest != null) {
            httpRequest.abort();
        }

    }

    @Override
    public void loadData(Object... objs) {
        notice = (String) objs[0];
        if ("recommend".equals(notice)) {
            httpRequest =
                    new HttpRequest(context, UrlManager.COLUMN_DOMAIN_READ, getRequestUrl(), null, this);
            httpRequest.setDataParseAdapter(new RecommendParser());
        } else {
            httpRequest =
                    new HttpRequest(context, UrlManager.COLUMN_DOMAIN_APPINFO, getRequestUrl(), null, this);
            httpRequest.setDataParseAdapter(new NoticeParser());
        }

        MyTask.runInBackground(httpRequest, true);

    }

}
